<?php
defined('BASEPATH') OR exit ('No direct script access allowed');

require (APPPATH . '/libraries/REST_Controller.php');
include_once 'db_functions_account.php';
class login extends REST_Controller {

	function user_get(){
		echo "only support method post";
	//$this->response("only support method post");		
	}

	function user_post() {
		// get account from client with post method;
		$username = $this->post('username');
		$password = $this->post('password');
		$device = $this->post('device');
		$gcm_regid = $this->post('gcm_regid');

		$db = new db_functions_account();
		$isLoginsucess = $db->checkAvaibleAcount($username, $password);
		$code = null;
		$result = null;
		if ($isLoginsucess) {
			
			if(strcmp($device,DEVICE_OTHER)!=0)
			$isUpdateRegidSucess=$db->updateGCMRegID($username,$gcm_regid);
			$code = 0;
			$result = "Login sucess!";
			$gcm_regid= $db->getRegIDFromUser($username);
		} else {
			$code = -1;
			$result = "Login fall!";
			
		}
		
		
		$re = array (
			'code' => $code,
			'result' => $result,
			'data' => $gcm_regid,

			
		);

		$this->response($re);

	}

}
?>
